home *** CD-ROM | disk | FTP | other *** search
/ Chip 2003 October / Chip Ekim 2003.iso / prog / code / contr / setup.exe / Disk1 / data1.cab / Paypal_En / Configuration / Commands / Edit PayPal Buy Now.js < prev    next >
Encoding:
JavaScript  |  2003-07-18  |  16.0 KB  |  450 lines

  1. /*-----------------------------------------------------------------------------
  2. -    File Name:
  3. -        Edit PayPal Single Item Purchase.js
  4. -
  5. -    Description:
  6. -        Functions for PayPal Single Item Purchase Advanced Mode.
  7. -
  8. -    This file contains proprietary and confidential information from WebAssist.com
  9. -    corporation.  Any unauthorized reuse, reproduction, or modification without
  10. -    the prior written consent of WebAssist.com is strictly prohibited.
  11. -
  12. -    Copyright 2001 WebAssist.com Corporation.  All rights reserved.
  13. ------------------------------------------------------------------------------*/
  14. var CURRENTPAGE = 0;
  15. var INSPECTIONPARAMS = false;
  16. var INTERFACE        = "advanced";
  17. var theOrig ="";
  18.  
  19. function commandButtons()     {
  20.   return new Array();
  21. }
  22.  
  23. function displayHelp()     {
  24.   INTERFACE   = "advanced";
  25.   displayContextHelp();
  26. }
  27.  
  28. function receiveArguments(charttype, ssRec, paramString)     {
  29.   INSPECTIONPARAMS = true;
  30. }
  31.  
  32. /* Initialize the UI.  First thing that's called on the body load event. */
  33. function initializeUI()     {
  34.   MM.setBusyCursor();
  35.   if (navigator.platform.toLowerCase().indexOf("mac") >= 0)     {
  36.     document.background.document.tabBgWin.src = "../Shared/PayPal/images/AdvancedBG_Mac.gif";
  37.     document.Tab0.document.tabBG.src = "../Shared/PayPal/images/tabBg_Mac.gif";
  38.     document.Tab1.document.tabBG.src = "../Shared/PayPal/images/longTabBg_Mac.gif";
  39.     document.Tab2.document.tabBG.src = "../Shared/PayPal/images/longTabBg_Mac.gif";
  40.     document.Tab3.document.tabBG.src = "../Shared/PayPal/images/longTabBg_Mac.gif";
  41.     document.background.style = "top:23px;";
  42.     
  43.     document.cancel.style = "position:absolute; width:70px; height:20px; z-index:94; left: 310px; top: 373px; visibility: visible";
  44.     document.cancel.document.btnCancel.style = "width:63; height:20; font-family:'Lucidia Grande'; font-size: 13px";
  45.     
  46.     document.OK.style = "position:absolute; width:70px; height:20px; z-index:94; left: 380px; top: 373px; visibility: visible";
  47.     document.OK.document.btnOK.style = "width:63; height:20; font-family:'Lucidia Grande'; font-size: 13px";
  48.     
  49.     document.help.style = "position:absolute; width:70px; height:20px; z-index:94; left: 240px; top: 373px; visibility: visible";
  50.     document.help.document.btnHelp.style = "width:63; height:20; font-family:'Lucidia Grande'; font-size: 13px";
  51.   
  52.     document.walogo.top = 375;
  53.     document.pplogo.top = 376;
  54.     }
  55.   document.OK.visibility = "visible";
  56.   document.cancel.visibility = "visible";
  57.   document.help.visibility = "visible";
  58.   document.background.visibility = "visible";
  59.   document.Tab0.visibility = "visible";
  60.   document.Tab1.visibility = "visible";
  61.   document.Tab2.visibility = "visible";
  62.   document.Tab3.visibility = "visible";
  63.   // Get values from the inspected node and populate our UI accordingly
  64.   var theDOM = dw.getDocumentDOM();
  65.   var theSelection = theDOM.getSelectedNode();
  66.   theOrig = unescape(theSelection.orig);
  67.   while (theSelection.tagName!="FORM" && theSelection.parentNode && theSelection.PPwholeForm != "true")  {
  68.     theSelection = theSelection.parentNode;
  69.   }
  70.   theOrig = theSelection.outerHTML;
  71.   var tempOrig = theOrig;
  72.   var firstInput = findOpenTag(tempOrig,"input");
  73.   while (firstInput != "")
  74.   {
  75.     var inputName = getTagProp(firstInput,"input","name");
  76.     var theVal = getTagProp(firstInput,"input","value");
  77.     switch (inputName.toLowerCase())
  78.     {
  79.       case "business":
  80.         if (theVal != "")   
  81.           document.generalWP.document.ppUID.value = theVal;      
  82.         break;
  83.  
  84.       case "item_name":
  85.         if (theVal != "")   
  86.           document.itemWP.document.itemName.value = theVal;      
  87.         break;
  88.  
  89.       case "item_number":
  90.         if (theVal != "")   
  91.           document.itemWP.document.itemID.value = theVal;      
  92.         break;
  93.  
  94.       case "amount":
  95.         if (theVal != "")   
  96.           document.itemWP.document.itemPrice.value = theVal;            
  97.         break;
  98.  
  99.       case "currency_code":
  100.         var theCurrency = document.itemWP.document.itemCurrency;      
  101.         for (var n=0; n<theCurrency.options.length; n++)
  102.         {
  103.             if (theVal == theCurrency.options[n].value)
  104.             {
  105.               theCurrency.selectedIndex = n;
  106.               break;
  107.             }
  108.         }              
  109.         break;                                                                                
  110.                 
  111.       case "shipping":
  112.         if (theVal != "")   
  113.           document.shippingWP.document.itemShipping.value = theVal;            
  114.         break;
  115.  
  116.       case "shipping2":
  117.         if (theVal != "")   
  118.           document.shippingWP.document.itemShipping2.value = theVal;            
  119.         break;
  120.  
  121.       case "handling":
  122.         if (theVal != "")   
  123.           document.shippingWP.document.itemHandling.value = theVal;            
  124.         break;
  125.                         
  126.       case "image_url":
  127.         if (isValidURL(theVal))   
  128.           document.generalWP.document.ppLogo.value = theVal;            
  129.         break;
  130.  
  131.       case "return":
  132.         if (isValidURL(theVal))   
  133.           document.generalWP.document.successURL.value = theVal;
  134.         break;
  135.         
  136.       case "cancel_return":
  137.         if (isValidURL(theVal))   
  138.           document.generalWP.document.cancelURL.value = theVal;      
  139.         break;
  140.   
  141.       case "undefined_quantity":
  142.         if (theVal == "1")
  143.         {
  144.           document.itemWP.document.quantityYes.checked = true;
  145.         }
  146.         break;
  147.  
  148.       case "no_shipping":
  149.         if (theVal == "1")
  150.         {
  151.           document.shippingWP.document.shippingNo[1].checked = true;
  152.         }
  153.         break;                                                                                
  154.  
  155.       case "no_note":
  156.         if (theVal == "1")
  157.         {
  158.           document.shippingWP.document.includeNote[1].checked = true;
  159.         }      
  160.         break;
  161.  
  162.       case "submit":  // button image URL
  163.         var theImg = document.buttonWP.document.sipimage;   
  164.         theVal = getTagProp(firstInput,"input","src");
  165.         var myImage = getTranslatedSIPImage(theVal);
  166.         if (myImage == CUSTOM_SIP_IMG)
  167.         {
  168.           myImage = "other";
  169.           document.buttonWP.document.othersipimage.value = theVal;
  170.         }
  171.         
  172.         for (var n=0; n<theImg.length; n++)
  173.         {
  174.             if (myImage == theImg[n].value)
  175.             {
  176.               theImg[n].checked = true;
  177.             }
  178.             else
  179.             {
  180.               theImg[n].checked = false;
  181.             }
  182.         }              
  183.         break;                                                                                
  184.                         
  185.       default:
  186.         break;
  187.     }   
  188.  
  189.     tempOrig = tempOrig.substring(tempOrig.indexOf(firstInput)+firstInput.length); 
  190.     firstInput = findOpenTag(tempOrig,"input");
  191.     
  192.   }  
  193.     
  194.   enableDisableOtherImage();
  195.   
  196.   // Go to the item details page
  197.   showPageNum(2);
  198.    
  199.   MM.clearBusyCursor();
  200.   
  201.   return true;
  202. }
  203.  
  204. /******************************** support functions ******************/
  205. function generateSIP()
  206. {
  207.   var myErrors = validateUI();
  208.   if (myErrors == "")
  209.   {
  210.     updateSIP(theOrig);
  211.   }
  212.   else
  213.   {
  214.     alert (myErrors);
  215.   }
  216.  
  217.   return;
  218. }
  219.  
  220. function updateSIP(formTag)  {
  221.   var theForm = formTag;
  222.   var undefinedQty = (document.itemWP.document.quantityYes.checked)?"1":"0";
  223.   var theBusiness = document.generalWP.document.ppUID.value;
  224.   var theItemName = document.itemWP.document.itemName.value;
  225.   var theItemNumber = document.itemWP.document.itemID.value;
  226.   var theAmount = document.itemWP.document.itemPrice.value;
  227.   var theShipping = document.shippingWP.document.itemShipping.value
  228.   var theShipping2 = document.shippingWP.document.itemShipping2.value
  229.   var theHandling = document.shippingWP.document.itemHandling.value
  230.   var theCurrencyCode = document.itemWP.document.itemCurrency.options[document.itemWP.document.itemCurrency.selectedIndex].value;
  231.   var theImageURL = document.generalWP.document.ppLogo.value;
  232.   var theReturn = document.generalWP.document.successURL.value;
  233.   var theCancel = document.generalWP.document.cancelURL.value
  234.   var theNoShip = (document.shippingWP.document.shippingNo[0].checked)?"0":"1";  
  235.   var theNoNote = (document.shippingWP.document.includeNote[1].checked)?"1":"0";
  236.   var theButtonImage = document.buttonWP.document.sipimage[0].value;
  237.   
  238.   if (theImageURL == "https://"  || theImageURL == "http://")
  239.     theImageURL = "";
  240.   if (theReturn == "https://"  || theReturn == "http://")
  241.     theReturn = "";
  242.   if (theCancel == "https://"  || theCancel == "http://")
  243.     theCancel = "";
  244.   
  245.   for (x in document.buttonWP.document.sipimage)  {
  246.     if (document.buttonWP.document.sipimage[x].checked)
  247.       theButtonImage = document.buttonWP.document.sipimage[x].value;
  248.   }
  249.   if (theButtonImage == "other")
  250.     theButtonImage = document.buttonWP.document.othersipimage.value;
  251.   else  
  252.     theButtonImage = "http://images.paypal.com/images/" + theButtonImage;
  253.   theForm = updateFormInput(theForm,"business",theBusiness);
  254.   theForm = updateFormInput(theForm,"undefined_quantity",undefinedQty);
  255.   theForm = updateFormInput(theForm,"item_name",theItemName);
  256.   theForm = updateFormInput(theForm,"item_number",theItemNumber);
  257.   theForm = updateFormInput(theForm,"amount",theAmount);
  258.   theForm = updateFormInput(theForm,"shipping",theShipping);
  259.   theForm = updateFormInput(theForm,"shipping2",theShipping2);
  260.   theForm = updateFormInput(theForm,"handling",theHandling);
  261.   theForm = updateFormInput(theForm,"currency_code",theCurrencyCode);
  262.   theForm = updateFormInput(theForm,"image_url",theImageURL);
  263.   theForm = updateFormInput(theForm,"return",theReturn);
  264.   theForm = updateFormInput(theForm,"cancel_return",theCancel);
  265.   theForm = updateFormInput(theForm,"no_shipping",theNoShip);
  266.   theForm = updateFormInput(theForm,"no_note",theNoNote);
  267.   theForm = updateFormInput(theForm,"bn",BNVersion);
  268.   theForm = updateImage(theForm,theButtonImage);
  269.   var theDOM = dreamweaver.getDocumentDOM();
  270.   var thePage = theDOM.documentElement.outerHTML;
  271.   var theSelection = theDOM.getSelectedNode();
  272.   var theOffsets = new Array();
  273.   while (theSelection.tagName!="FORM" && theSelection.PPwholeForm!="true")  {
  274.     theSelection = theSelection.parentNode;
  275.   }
  276.   theDOM.setSelectedNode(theSelection);
  277.   theDOM.insertHTML(theForm);
  278.   closeWindow();
  279. }
  280.  
  281. function updateImage(formHTML,image)  {
  282.   var theInput = /<input\s[^<]*type=(['"])image\1/i;
  283.   if (formHTML.search(theInput)>=0)  {
  284.     var theTag = findOpenTag(formHTML.substring(formHTML.search(theInput)),"input");
  285.     formHTML = formHTML.substring(0,formHTML.indexOf(theTag)) + updateTagProp(theTag,"input","src",image) + formHTML.substring(formHTML.indexOf(theTag)+theTag.length);
  286.   }
  287.   else  {
  288.     formHTML = formHTML.substring(0,formHTML.search(/\s*<\/form>/i))+'\r\n<input type="image" name="submit" src="'+image+'" border="0" alt="Make payments with PayPal - it\'s fast, free and secure!">'+formHTML.substring(formHTML.search(/\s*<\/form>/i));
  289.   }
  290.   return formHTML;
  291. }
  292.  
  293. function updateFormInput(formHTML,fieldName,fieldValue)  {
  294.   var theInput = new RegExp('<input\\s[^<]*name=([\'"]?)'+fieldName+'\\1',"i");
  295.   if (formHTML.search(theInput)>=0)  {
  296.     var theTag = findOpenTag(formHTML.substring(formHTML.search(theInput)),"input");
  297.     if (fieldValue!="")
  298.       formHTML = formHTML.substring(0,formHTML.indexOf(theTag)) + updateTagProp(theTag,"input","value",fieldValue) + formHTML.substring(formHTML.indexOf(theTag)+theTag.length);
  299.     else
  300.       formHTML = formHTML.substring(0,formHTML.indexOf(theTag)) + formHTML.substring(formHTML.indexOf(theTag)+theTag.length);
  301.   }
  302.   else  {
  303.     if (fieldValue!="")
  304.       formHTML = formHTML.substring(0,formHTML.search(/\s*<\/form>/i))+'\r\n<input type="hidden" name="'+fieldName+'" value="'+fieldValue+'">'+formHTML.substring(formHTML.search(/\s*<\/form>/i));
  305.   }
  306.   return formHTML;
  307. }
  308.  
  309.  
  310.  
  311. function validateUI()    {
  312.   var errMsg = "";
  313.   var tempErrMsg = "";
  314.   var myAmount = document.itemWP.document.itemPrice.value;
  315.   var myShipping = document.shippingWP.document.itemShipping.value;
  316.   var myShipping2 = document.shippingWP.document.itemShipping2.value;
  317.   var myHandling = document.shippingWP.document.itemHandling.value;  
  318.   var accountErrMsg = validatePPUID();
  319.   if (accountErrMsg != "")
  320.   {
  321.     errMsg += "PayPal Account " + accountErrMsg;
  322.   }
  323.   
  324.   if (myAmount != "")
  325.   {
  326.     tempErrMsg = validateItemPrice(myAmount);  
  327.     if (tempErrMsg != "")
  328.     {
  329.       errMsg += "Item Price " + tempErrMsg;    
  330.     }
  331.   }
  332.  
  333.   if (myShipping != "")
  334.   {
  335.     tempErrMsg = validateAmount(myShipping);  
  336.     if (tempErrMsg != "")
  337.     {
  338.       errMsg += "Base Shipping " + tempErrMsg;    
  339.     }
  340.   }
  341.  
  342.   if (myShipping2 != "")
  343.   {
  344.     tempErrMsg = validateAmount(myShipping2);  
  345.     if (tempErrMsg != "")
  346.     {
  347.       errMsg += "Extra Shipping " + tempErrMsg;    
  348.     }
  349.   }
  350.  
  351.   if (myHandling != "")
  352.   {
  353.     tempErrMsg = validateAmount(myHandling);  
  354.     if (tempErrMsg != "")
  355.     {
  356.       errMsg += "Handling " + tempErrMsg;    
  357.     }
  358.   }
  359.         
  360.   if ( errMsg != "" )
  361.   {
  362.     errMsg = "The following errors were found:\n\n" + errMsg;
  363.   }
  364.   
  365.   return errMsg;
  366. }
  367.  
  368. function enableDisableOtherImage()     {
  369.   var myImage = document.buttonWP.document.sipimage;
  370.   for (var n=0; n<myImage.length; n++)
  371.   {
  372.     if (myImage[n].checked)
  373.     {
  374.       if (myImage[n].value == "other")
  375.       {
  376.         document.buttonWP.document.othersipimage.disabled = "enabled";
  377.       }
  378.       else
  379.       {
  380.         document.buttonWP.document.othersipimage.disabled = "disabled";
  381.       }
  382.     }
  383.   }
  384. }
  385.  
  386. /******************************** PAGE FUNCTIONS ********************************/
  387. function Pg0_Load()     {
  388.   document.generalWP.visibility = "visible";
  389.   setTimeout("document.generalWP.document.ppUID.focus()",500);
  390.   return true;
  391. }
  392. function Pg0_unLoad()     {
  393.   document.generalWP.visibility = "hidden";
  394.   document.generalWP.visibility = "visible";
  395.   document.generalWP.visibility = "hidden";
  396.   return true;
  397. }
  398.  
  399. function Pg1_Load()     {
  400.   document.buttonWP.visibility = "visible";
  401.   return true;
  402. }
  403. function Pg1_unLoad()     {
  404.   document.buttonWP.visibility = "hidden";
  405.   document.buttonWP.visibility = "visible";
  406.   document.buttonWP.visibility = "hidden";
  407.   return true;
  408. }
  409.  
  410. function Pg2_Load()     {
  411.   document.itemWP.visibility = "visible";
  412.   setTimeout("document.itemWP.document.itemName.focus()",500);
  413.   return true;
  414. }
  415. function Pg2_unLoad()     {
  416.   document.itemWP.visibility = "hidden";
  417.   document.itemWP.visibility = "visible";
  418.   document.itemWP.visibility = "hidden";
  419.   return true;
  420. }
  421.  
  422. function Pg3_Load()     {
  423.   document.shippingWP.visibility = "visible";
  424.   setTimeout("document.shippingWP.document.itemShipping.focus()",500);
  425.   return true;
  426. }
  427. function Pg3_unLoad()     {
  428.   document.shippingWP.visibility = "hidden";
  429.   document.shippingWP.visibility = "visible";
  430.   document.shippingWP.visibility = "hidden";
  431.   return true;
  432. }
  433.  
  434. function showPageNum(pageNum)  {
  435.   eval("Pg"+CURRENTPAGE+"_unLoad()");
  436.   if (navigator.platform.toLowerCase().indexOf("mac") >= 0)     {
  437.     eval("document.Tab"+CURRENTPAGE+".document.tabBG.src = document.Tab"+CURRENTPAGE+".document.tabBG.src.substring(0,document.Tab"+CURRENTPAGE+".document.tabBG.src.toLowerCase().lastIndexOf('tabbg'))+'tabBg_Mac.gif'");
  438.   }
  439.   else  {
  440.     eval("document.Tab"+CURRENTPAGE+".document.tabBG.src = document.Tab"+CURRENTPAGE+".document.tabBG.src.substring(0,document.Tab"+CURRENTPAGE+".document.tabBG.src.toLowerCase().lastIndexOf('tabbg'))+'tabBg.gif'");
  441.   }
  442.   CURRENTPAGE = pageNum;
  443.    if (navigator.platform.toLowerCase().indexOf("mac") >= 0)     {
  444.     eval("document.Tab"+CURRENTPAGE+".document.tabBG.src = document.Tab"+CURRENTPAGE+".document.tabBG.src.substring(0,document.Tab"+CURRENTPAGE+".document.tabBG.src.toLowerCase().lastIndexOf('tabbg'))+'tabBgSel_Mac.gif'");
  445.    }
  446.   else  {  
  447.     eval("document.Tab"+CURRENTPAGE+".document.tabBG.src = document.Tab"+CURRENTPAGE+".document.tabBG.src.substring(0,document.Tab"+CURRENTPAGE+".document.tabBG.src.toLowerCase().lastIndexOf('tabbg'))+'tabBgSel.gif'");
  448.   }
  449.   eval("Pg"+CURRENTPAGE+"_Load()");
  450. }